package org.itboys.manager;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.itboys.mongodb.utils.page.Page;
import org.itboys.seller.entity.Seller;
import org.itboys.seller.service.SellerService;
import org.itboys.weixin.entity.WeixinConfig;
import org.itboys.weixin.service.WeixinConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商家和微信的关联
 * @author weisky
 *
 * 2016年4月12日
 */
@Service
public class SellerWeixinService {

	@Autowired
	private SellerService sellerService;
	@Autowired
	private WeixinConfigService weixinConfigService;
	
	public Page<Seller> sellerListByPage(Map<String, Object> param, HttpServletRequest request){
		Page<Seller> page = sellerService.pageQuery(param, request);
		if(page != null && page.getData() != null){
			page.getData().forEach(sl -> {//设置店铺关联的微信名称
				if(sl.getWeixinId() != null){
					WeixinConfig wc = weixinConfigService.getById(sl.getWeixinId());
					if(wc != null){
						sl.setWeixinName(wc.getName());
					}
				}
			});
		}
		return page;
	}
}
